(function () {
    //严谨模式 检查所有错误
    'use strict';
    //document 为要hook的对象   这里是hook的cookie
    Object.defineProperty(document, 'cookie', {
        //hook set方法也就是赋值的方法
        //当前也可以hook get方法
        get: function () {
            return catvm.memory.cookie
        },
        set: function (val) {
            //这样就可以快速给下面这个代码行下断点
            //从而快速定位设置cookie的代码
            console.log('Hook捕获到cookie设置->', val);
            // 去除 Max-Age 与expires 的影响
            // var vals = val.split(";")
            // var is_v = ""
            // for (let i = 0; i < vals.length; i++) {
            //     if (vals[i].indexOf("Max-Age") === -1 && vals[i].indexOf("expires") === -1 && vals[i].indexOf("path=") === -1) {
            //         is_v += vals[i] + ";"
            //     }
            // }
            // if (is_v.length !== 0) {
            //     catvm.memory.cookie += is_v
            // }
            var d = new Date();
            d.setTime(d.getTime() + -0.0002 * 1000);
            var expires = "expires=" + d.toUTCString();
            if (val.indexOf(expires) === -1) {
                catvm.memory.cookie += '|' + val
            }
        }
    });
})();

(function () {
    //严谨模式 检查所有错误
    'use strict';
    Object.defineProperty(Element.prototype, 'innerHTML', {
        set: function (val) {
            //
            debugger;
            if (typeof val === "string") {
                var shuxin = val.toString().split(">")
                var name_first = (shuxin[0] + "").split(" ")[0] + "/>"
                var inte = val.slice(val.indexOf('">') + 2, val.indexOf(name_first) - name_first.length + 1)
                var name = (shuxin[0] + "").split(" ")[0].replace("<", "")
                var shuxin_1 = (shuxin[0] + "").split(" ").slice(1, (shuxin[0] + "").split(" ").length)
                var shuxin_2 = {
                    innerHTML: inte
                }
                for (let i = 0; i < shuxin_1.length; i++) {
                    shuxin_2[shuxin_1[i].split("=")[0]] = shuxin_1[i].split("=")[1].replace('"', "").replace('"', "")
                    if (shuxin_1[i].split("=")[0] === "href") {
                        shuxin_2["href"] = location.origin + shuxin_2["href"]
                    }
                }
                var ele = catvm.memory.htmlelements[name](shuxin_2);
                this.son = ele;
                ele.father = this;
            }
            console.log(val)
            this.innerHTMLs = val
            // this.innerHTML = val
        },
        get :function () {
            return this.innerHTMLs
        }
    });
})();
(function () {
    Object.defineProperty(HTMLIFrameElement.prototype, 'contentDocument', {
        get: function () {
            if (this.father !== undefined) {
                return document
            } else {
                return null
            }
        }
    })
})();
(function () {
    Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {
        get: function () {
            if (this.father !== undefined) {
                return window
            } else {
                return null
            }
        }
    })
})();
(function () {
    //严谨模式 检查所有错误
    'use strict';
    Object.defineProperty(Node.prototype, 'firstChild', {
        get: function () {
            // debugger
            // console.log(this.son)
            return this.son
        },
    });
})();
// hook
_eval = eval;
eval = function (x) {
    console.log(x)
    debugger;
    return _eval(x)
}
_Function = Function;

Function = function (x) {
    var args = Array.prototype.slice.call(arguments, 0, -1).join(","), src = arguments[arguments.length - 1]
    console.log(src);
    debugger;
    return _Function.apply(this, arguments)
    // debugger;
    // return _Function(x)
}